<?php
  class editor_model extends Model{
      function editor_model(){
          parent::Model();
      }
      function getAllFile($num,$offset){
          $ar_img = array('gif','png','jpg','jpeg');
          $this->db->where_in('ext',$ar_img);
          $this->db->order_by('id','DESC');
          $query = $this->db->get('filedata',$num,$offset);
          return $query->result();
      }
      function getNumFile(){
          $query = $this->db->get('filedata');
          return $query->num_rows();
      } 
      
      function upload(){
          $this->load->library('upload_library');
          $size = $_FILES["filedata"]["size"];
          if($size > 0){
              $filedata = $this->upload_library->uploadfile();
              if($filedata!=''){
                  $file = explode('*',$filedata);
                  $url = $file[0];
                  $size = $file[1];
                  $ext = $file[2];
                  $data = array(
                    'name' => $file[3],
                    'url' => $url,
                    'size' => $size,
                    'ext' => $ext
                  );
                  $this->db->insert('filedata',$data);
                  return $url;
              }
          }else{
              return '';
          }
      }       
  }
?>
